<template>
  <div>
    <el-dialog v-bind="$attrs" v-on="$listeners" :visible.sync="showDialog" @open="onOpen" @close="onClose" title="添加用户">
      <el-row :gutter="15">
        <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="80px">
          <el-col :span="24">
          </el-col>
          <el-col :span="12">
            <el-form-item label="角色Id" prop="rId">
              <el-input v-model="formData.rId" placeholder="请输入角色Id" clearable :style="{width: '100%'}">
              </el-input>
            </el-form-item>
            <el-form-item label="角色" prop="roleName">
              <el-input v-model="formData.roleName" placeholder="请输入角色" clearable :style="{width: '100%'}">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="角色详情" prop="roleDesc">
              <el-input v-model="formData.roleDesc" placeholder="请输入角色详情" clearable :style="{width: '100%'}">
              </el-input>
            </el-form-item>
          </el-col>

        </el-form>
      </el-row>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import ImageCropper from '../../components/ImageCropper'
  import PanThumb from '../../components/PanThumb'

  export default {
    name: 'RoleAdd',
    components: {ImageCropper, PanThumb},
    // 接受父组件传递的值
    props:{
      addVisible:{
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        formData: {
          rId: undefined,
          roleName: undefined,
          roleDesc: undefined,
        },
        // 控制弹出框显示隐藏
        showDialog:false,
        imagecropperShow: false, // 是否显示上传组件
        imagecropperKey: 0, // 上传组件id
        image: 'http://47.93.37.158:8888/group1/M00/00/00/rBklB2B6dKSAImyzAAIcU_dRVxE613.png',
        rules: {
          rId: [{
            required: true,
            message: '请输入角色Id',
            trigger: 'blur'
          }]
          ,roleName: [{
            required: false,
            message: '请输入角色',
            trigger: 'blur'
          }],
          roleDesc: [{
            required: true,
            message: '请选择角色详情',
            trigger: 'blur'
          }],
        },
        field101Action: 'https://jsonplaceholder.typicode.com/posts/',
        field101fileList: [],
        sexOptions: [{
          "label": "帅哥",
          "value": 1
        }, {
          "label": "美女",
          "value": 2
        }],
      }
    },
    computed: {},
    watch: {
      // 监听 addOrUpdateVisible 改变
      addVisible(oldVal,newVal){
        this.showDialog = this.addVisible
      },
    },
    created() {},
    mounted() {},
    methods: {

      onOpen() {

      },
      onClose() {
        this.$refs['elForm'].resetFields()
        this.$emit('changeShow', 'false')
      },
      close() {
        this.$emit('changeShow', 'false')
      },
      handelConfirm() {
        this.$refs['elForm'].validate(valid => {
          if (!valid) return;
          this.$axios.post("/sys/roles",this.formData).then((response) => {
          });
          // this.close();
          location.reload();
        })
      }
    }
  }
</script>
<style>


</style>
